package com.example.demo.config;

import org.springframework.context.annotation.Configuration;
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;
import org.springframework.security.web.authentication.UsernamePasswordAuthenticationFilter;

/**
 * @author admin
 */
@Configuration
@EnableWebSecurity
public class SecurityConfig extends WebSecurityConfigurerAdapter {

    @Override
    protected void configure(HttpSecurity http) throws Exception {
        System.out.println("被使用了");
        http
                .authorizeRequests()
                .antMatchers("/api/auth/**").permitAll()       // 放行登录和注册接口
                .antMatchers("/login.html", "/users.html").permitAll() // 放行静态页面
                .antMatchers("/pay/notify").permitAll()        // 放行支付宝回调接口
                .antMatchers("/pay/**").permitAll()
                .anyRequest().authenticated()                  // 其他请求需要认证
                .and()
                .addFilterBefore(new JwtAuthenticationFilter(), UsernamePasswordAuthenticationFilter.class)
                .csrf().disable();                                 // 保持 CSRF 禁用
    }
}